﻿using Publicuse.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Publicuse.Util
{
    public class DataCacheUtil
    {
        private readonly static Dictionary<string, CommonResult> list = null;


        private readonly static DataCacheUtil cacheUtil = null;

        static DataCacheUtil()
        {
            cacheUtil = new DataCacheUtil();
            list = new Dictionary<string, CommonResult>();
        }

        public static DataCacheUtil GetDataCacheUtil { get { return cacheUtil; } }

        private static object lockadd = new object();

        public void AddData(string key, CommonResult data)
        {
            lock (lockadd)
            {
                if (list.ContainsKey(key))
                {
                    list.Remove(key);
                }
                list.Add(key, data);
            }
        }

        public void RemoveData(string key)
        {
            if (list.ContainsKey(key))
            {
                list.Remove(key);
            }
        }

        public void GetData(string key, out CommonResult data)
        {
            list.TryGetValue(key, out data);
        }

        public void ClearData()
        {
            list.Clear();
        }
    }
}
